package org.kealinghornets.nxtdroid;

import org.kealinghornets.nxtdroid.NXT.LightSensor;
import org.kealinghornets.nxtdroid.NXT.NXTThread;

/**
 * Created by jychuah on 11/3/13.
 */
public class MyNXTThread extends NXTThread {

    int state = 1;
    LightSensor eyeball;

    public MyNXTThread() {
        setNXTThreadName("Bridge Crosser");
    }

    public void run() {

        eyeball = getActiveLightSensor(PORT_1);
        while (state != -1) {
            switch (state) {
                case 1:
                    do_state_1();
                    break;
                case 2:
                    do_state_2();
                    break;
                case 3:
                    do_state_3();
                    break;
                case 4:
                    do_state_4();
                    break;
                case 5:
                    do_state_5();
                    break;
                case 6:
                    do_state_6();
                    break;
                case 7:
                    do__state_7();
                    break;

                default:
                    state = -1;
                    break;
            }
        }
    }

    public void do_state_1() {


        log("im_in_state_1");
        runMotor(PORT_A, -100);runMotor(PORT_B, 98);
        wait(1400);
        stopMotor(PORT_A);stopMotor(PORT_B);
        eyeball = getActiveLightSensor(PORT_1);
        if (eyeball.getLightValue() > 325) {
        state = 2;
    }

    else

    {
        state = 3;
    }
}

    public void do_state_2() {
        // do some stuff
        log("im_in_state_2");
        runMotor(PORT_A,-98);runMotor(PORT_B,-100);
        wait(3750);
        stopMotor(PORT_A); stopMotor(PORT_B);
        runMotor(PORT_A,100);runMotor(PORT_B,-98);
        wait(1400);
        stopMotor(PORT_A); stopMotor(PORT_B);
        runMotor(PORT_A,-100); runMotor(PORT_B,-98);
        wait(7500);
        stopMotor(PORT_A); stopMotor(PORT_B);
        runMotor(PORT_A,-100);runMotor(PORT_B,98);
        wait(1400);
        stopMotor(PORT_A); stopMotor(PORT_B);
        runMotor(PORT_A,-100);runMotor(PORT_B,-98);
        wait(3750);
        stopMotor(PORT_A);stopMotor(PORT_B);
        eyeball = getActiveLightSensor(PORT_1);
        if (eyeball.getLightValue() >  230){
            state = 5;
        }
        else
        {
            state = 4;
        }
    }
        public void do_state_3 () {
            // do some st;uff
         log("im in state 3");
            runMotor(PORT_A,-100);  runMotor(PORT_B,98);
            wait(2800);
            stopMotor(PORT_A); stopMotor(PORT_B);
            runMotor(PORT_A,-100); runMotor(PORT_B,-98);
            wait(3750);
            stopMotor(PORT_A); stopMotor(PORT_B);
            runMotor(PORT_A,-100); runMotor(PORT_B,98);
            wait(1400);
            stopMotor(PORT_A);stopMotor(PORT_B);
            runMotor(PORT_A,-100);runMotor(PORT_B,-98);
            wait(7500);
            stopMotor(PORT_A); stopMotor(PORT_B);
            runMotor(PORT_A,-100); runMotor(PORT_B,98);
            wait(1400);
            stopMotor(PORT_A); stopMotor(PORT_B);
            runMotor(PORT_A,-100);runMotor(PORT_B,-100);
            wait(3750);
            stopMotor(PORT_A);stopMotor(PORT_B);
            eyeball = getActiveLightSensor(PORT_1);
            if (eyeball.getLightValue() >  230){
                state = 5;
            }
            else
            {
                state = 4;





            }




        }
            public void
            do_state_4() {
                log("I'm in state 4");
            }
            public void do_state_5 () {
                log("im in state 5");
                runMotor(PORT_A,-100); runMotor(PORT_B,-98);
                wait(6750);
                stopMotor(PORT_A); stopMotor(PORT_B);
                runMotor(PORT_A,-100); runMotor(PORT_B,98);
                wait(1400);
                stopMotor(PORT_A); stopMotor(PORT_B);
                runMotor(PORT_A,-100); runMotor(PORT_B,-98);
                wait(6000);
                stopMotor(PORT_A); stopMotor(PORT_B);
                eyeball = getActiveLightSensor(PORT_1);
                if (eyeball.getLightValue() >  547){
                    state = 7;
                }
                else
                {
                    state = 6;
                }

            }
            public void do_state_6 () {
                log("im in state 6");
                runMotor(PORT_A,-100); runMotor(PORT_B,98);
                wait(2800);
                stopMotor(PORT_A); stopMotor(PORT_B);
                runMotor(PORT_A,-100); runMotor(PORT_B,-98);
                wait(12000);
                stopMotor(PORT_A); stopMotor(PORT_B);
                eyeball = getActiveLightSensor(PORT_1);
                if (eyeball.getLightValue() >  540){
                    state = 7;
                }
                else
                {
                    state = 7;
                }

            }
            public void do__state_7 () {

                log("im in state 7");
             runMotor(PORT_C,-100);
                wait(1000);
                stopMotor(PORT_C);
                state = -1;
            }
    }






